﻿<%--
  Created by IntelliJ IDEA.
  User: 27716
  Date: 2024/10/24
  Time: 19:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改</title>
    <script src="../../static/js/jquery-1.8.2.min.js"></script>
    <link rel="stylesheet" href="../../static/css/css.css">
    <script>
        $(function (){
            findByIn();
        })
        function findByIn(){
            //1.获取值
            let rid = $("#rid").val();
            //2.组装对象
            let obj = {rid:rid};
            //发起异步请求
            $.ajax({
                url:"/role/findByIn",
                type:"post",
                data:{reqInfos:JSON.stringify(obj)},
                dataType:"json",
                success(res){
                    $("#name").val(res.username);
                    $("#remark").val(res.remark);
                },
                error(){
                    alert("滚出去!!!");
                }
            })
        }
    </script>
</head>
<body>
<input type="hidden" value="${param.rid}" id="rid">
角色名：<input type="text" id="name"> <br>
备注： <input type="text" id="remark"> <br>
<input type="button" value="修改" id="toUpd">
</body>
<script>
    $("#toUpd").click(function () {
        let rid = $("#rid").val();
        let name = $("#name").val();
        let remark = $("#remark").val();
        if(!rid || !name ||!remark){
            alert("数据不能重复");
            return;
        }
        let obj = {rid:rid,username:name,remark:remark};
        $.ajax({
            url:"/role/getUpd",
            type: "post",
            data: {reqInfos:JSON.stringify(obj)},
            dataType: "json",
            success(res) {
                if(res === 200){
                    alert("修改成功");
                    location.href = "list.jsp";
                }
            },
            error() {
                alert("无法修改")
            }
        })
    })
</script>
</html>
